home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / userconf / privi.c < prev    next >
C/C++ Source or Header  |  1996-07-20  |  3KB  |  110 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "../misc/misc.h"
  4. #include "../dialog/dialog.h"
  5. #include "userconf.h"
  6. #include "userconf.m"
  7.  
  8. /* #Specification: privileges / intro
  9.     The privilege system of Linuxconf let you give special power to
  10.     end user. Linuxconf manage quite a few feature of a system and
  11.     each component of linuxconf can associate itself with a special
  12.     privilege. When trying to perform something special, the component
  13.     ask permission to the perm_access() function passing it the
  14.     PRIVILEGE object which fit its security scheme.
  15.  
  16.     When perm_access() is called, either the root password or the user
  17.     password must be supplied. If the user has this privilege, then
  18.     operation can continue.
  19.  
  20.     The privilege feature is unique to linuxconf. A privileged user
  21.     has no special UID or GID. Out of linuxconf, it is a plain normal
  22.     users.
  23.  
  24.     This concept is expect to grow in the following directions
  25.  
  26.     #
  27.         -Assigning privilege to group.
  28.         -Allowing some flexibility to user authentication. For exemple
  29.          one user won't have to provide his password if he is accessing
  30.          linuxconf in such or such context. This would help make linux
  31.          much more user friendly.
  32.         -Assigning password to privilege
  33.     #
  34.  
  35.     PRIVILEGE objects are always static and link together, so we know
  36.     at run time all the privilege that exist in the application. This
  37.     is used to dunamically create the USER configuration dialog.
  38. */
  39.  
  40. static PRIVILEGE *first;
  41.  
  42. PUBLIC PRIVILEGE::PRIVILEGE(const char *_id)
  43. {
  44.     id.setfrom (_id);
  45.     next = first;
  46.     first = this;
  47. }
  48.  
  49. /* #Specification: privilege / default type
  50.     A standard privilege is associate
  51. */
  52. class PRIVILEGE_DATA_SIMPLE: public PRIVILEGE_DATA{
  53.     /*~PROTOBEG~ PRIVILEGE_DATA_SIMPLE */
  54. public:
  55.     PRIVILEGE_DATA_SIMPLE (const char *line);
  56.     PRIVILEGE_DATA_SIMPLE (void);
  57.     void format_ascii (char *line);
  58.     void setdialog (DIALOG&dia);
  59.     int validate (void);
  60.     /*~PROTOEND~ PRIVILEGE_DATA_SIMPLE */
  61. };
  62.  
  63. PUBLIC PRIVILEGE_DATA_SIMPLE::PRIVILEGE_DATA_SIMPLE(const char *line)
  64. {
  65.     int x,y;
  66.     sscanf (line,"%d %d",&x,&y);
  67.     active = (char)x;
  68.     authenticate = (char)y;
  69. }
  70. PUBLIC PRIVILEGE_DATA_SIMPLE::PRIVILEGE_DATA_SIMPLE()
  71. {
  72.     active = 0;
  73.     authenticate = 1;
  74. }
  75.     
  76. /*
  77.     format in ascii so the information may be stored in /etc/conf.linuxconf
  78. */
  79. PUBLIC void PRIVILEGE_DATA_SIMPLE::format_ascii(char *line)
  80. {
  81.     sprintf (line,"%d %d",active,authenticate);
  82. }
  83. /*
  84.     Return 0 if the privilege is not granted to this users.
  85.     Return 1 if the privilege is granted, but user must authenticate
  86.     Return 2 if the privilege is granted, no question ask!
  87. */
  88. PUBLIC int PRIVILEGE_DATA_SIMPLE::validate()
  89. {
  90.     int ret = 0;
  91.     if (active){
  92.         ret = 1;
  93.         if (!authenticate) ret = 2;
  94.     }
  95.     return ret;
  96. }
  97. PUBLIC void PRIVILEGE_DATA_SIMPLE::setdialog(DIALOG &dia)
  98. {
  99.     dia.newf_chk (MSG_U(F_PRIVENABLE,"Grant"),active,"");
  100.     dia.newf_chk ("",authenticate,MSG_U(F_AUTHENTICATE,"Must authenticate"));
  101. }
  102. /*
  103.     A PRIVILEGE_DATA object to edit and control that kind
  104.     of privilege. line contain raw info used to initialise the new object.
  105. */
  106. PUBLIC VIRTUAL PRIVILEGE_DATA *PRIVILEGE::getdata (const char *line)
  107. {
  108.     return new PRIVILEGE_DATA_SIMPLE (line);
  109. }
  110.